<?php /* 创建房间 */
require_once('conn.inc.php');
@$conn		=		mysql_connect($db_host,$db_user,$db_pwd);
mysql_query("set names 'utf8'");
mysql_select_db($db_name);

@$id 	=	 	$_POST["id"];
@$tx	=		$_POST["tx"];

$find = "select * from home where fid='$id' && state='1' ";
$result = mysql_query($find);
$num_rows = mysql_num_rows($result);
if ($num_rows >= 1) {
	$rc = array('code'=>0);
	echo json_encode($rc);										//已经创建过房间
}elseif ($num_rows == 0){
	@$hid 			=	rand(10000,99999);
	@$topic			=	$_POST['topic'];
	@$nop			=	$_POST['nop'];
	@$place			=	$_POST['place'];
	@$activitytime	=	$_POST['activitytime'];
	@$posttime		=	time();									//建房时间
	@$about			=	$_POST['about'];
	@$fid			=	$_POST['id'];
	@$pic			=	$_POST['pic'];
	@$state			=	1;
	
	$fhid = "select * from home where hid='$hid'";
	$rhid = mysql_query($find);
	$nhid = mysql_num_rows($rhid);
	if ($nhid >= 1) {
		$rc = array('code'=>1);
		echo json_encode($rc);										//请重试。（房间号冲突）
	}else{
		$sql 	=	 "insert into home (hid,topic,nop,place,activitytime,posttime,about,fid,pic,state) values 
		('$hid','$topic','$nop','$place','$activitytime','$posttime','$about','$fid', '$pic','$state')";
			$rs = mysql_query($sql);
			$rh = mysql_affected_rows();					
		$sql2	=	"insert into hometeam (zid,fid,hid,state,posttime) values 
		('$id','$id','$hid','$state','$posttime')";
			$rs2 = mysql_query($sql2);
			$rh2 = mysql_affected_rows();
			if ($rh == 1 && $rh2 == 1) {
				$rc = array('code'=>2);
				echo json_encode($rc);			//成功
			}else {
				$rc = array('code'=>3);
				echo json_encode($rc);			//失败
			}
	}
	
}
